unit ExceldenMailGonder;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FormClass, XPMan, StdActns, ActnList, StdCtrls, Buttons,
  ExtCtrls, fcStatusBar, Grids, BaseGrid, AdvGrid, DB, ADODB, Menus, AdvObj,
  siComp;

type
  TfmExceldenMailGonder = class(TfmFormClass)
    AGrid: TAdvStringGrid;
    StBar: TfcStatusBar;
    Panel2: TPanel;
    btExcelImport: TBitBtn;
    btAktar: TBitBtn;
    oDlg: TOpenDialog;
    aqSendMail: TADOQuery;
    SDlg: TSaveDialog;
    PopupMenu1: TPopupMenu;
    ExportExcel1: TMenuItem;
    procedure btExcelImportClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btAktarClick(Sender: TObject);
    procedure ExportExcel1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmExceldenMailGonder: TfmExceldenMailGonder;

implementation
uses UnitGenel, Data, Boxes, UnitOrtak, ana1;
{$R *.dfm}

procedure TfmExceldenMailGonder.btExcelImportClick(Sender: TObject);
begin
  inherited;
  if (oDlg.Execute) then
  begin
    AGrid.Clear;
    btAktar.Enabled := False;
    ExcelImport(oDlg.FileName, AGrid, False);
    btAktar.Enabled := AGrid.RowCount > 1;
  end;
end;

procedure TfmExceldenMailGonder.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  fmExceldenMailGonder := nil;
end;

procedure TfmExceldenMailGonder.btAktarClick(Sender: TObject);
var
  Counter: integer;
begin
  inherited;
  for Counter := 1 to AGrid.RowCount - 1 do
  begin
    Application.ProcessMessages;
    if Trim(AGrid.Cells[2, Counter]) <> '' then
      if anaform.MailSend.SendMailOffline(AGrid.Cells[1, Counter], AGrid.Cells[2, Counter], AGrid.Cells[3, Counter], AGrid.Cells[4, Counter]) then
        AGrid.Cells[0, Counter] := 'OK'
  end;
end;

procedure TfmExceldenMailGonder.ExportExcel1Click(Sender: TObject);
begin
  inherited;
  if SDlg.Execute then
    AGrid.SaveToXLS(SDlg.FileName, True);
end;

end.
